$(function () {

    var hrefUrl = window.location.pathname.toString().substring(1)

    var headList = [
        {
            type: 1,
            name: '首页',
            href: 'index.html'
        },
        {
            type: 2,
            name: '教学',
            href: 'teach.html'
        },
        {
            type: 3,
            name: '行测',
            href: 'line.html'
        },
        {
            type: 4,
            name: '参考题库',
            href: '//practice-api.bjjixin.cn/common/v1/index/download',
            target: true
        },
        {
            type: 5,
            name: '报名入口',
            href: 'apply.html',
        }
    ]
    var headTpl = '';
    headTpl += ' <div class="navbar navbar-default navbar-static-top">';
    headTpl += '     <div class="container clearfix">';
    headTpl += '         <div class="navbar-header">';
    headTpl += '             <a class="navbar-brand" href="index.html"><img src="../images/logo/logo.png" class="logo_img" alt="logo" width="54" height="53">';
    headTpl += '             <div class="logo_txt">'
    headTpl += '             <h1>远 大 都 教 育</h1>';
    headTpl += '             <p class="desc">11年专注国家电网考试培训</p>'
    headTpl += '             </div>'
    headTpl += '             </a>';
    headTpl += '         </div>';
    headTpl += '         <div class="navbar-collapse">';
    headTpl += '        <div class="login_box">';
    headTpl += '            <em class="login_btndis login_btn">登录</em>&nbsp;&nbsp;<i class="line">/</i>&nbsp;&nbsp;';
    headTpl += '            <em class="login_txt_b">退出</em>&nbsp;&nbsp;<i class="line">/</i>&nbsp;&nbsp;<a href="personal_center.html" target="_blank" class="admin_a">个人中心</a>';
    headTpl += '        </div>';
    headTpl += '             <ul class="nav_ul clearfix">';
    for (var i = 0; i < headList.length; i++) {
        if (hrefUrl == headList[i].href) {
            headTpl += '    <li class="active" data-type="' + headList[i].type + '">'

        } else {
            headTpl += '    <li class="" data-type="' + headList[i].type + '">'
        }

        let target = (typeof headList[i].target !== "undefined") ? '_blank' : '_self';

        if (window.location.pathname.substring(1) == headList[i].href) {
            headTpl += '        <a href="' + headList[i].href + '" class="nav_cur" target="' + target + '">' + headList[i].name + '</a>'
        } else {
            headTpl += '        <a href="' + headList[i].href + '"  target="' + target + '">' + headList[i].name + '</a>'
        }

        headTpl += '    </li>'
    }
    headTpl += '             </ul>'
    headTpl += '         </div>'
    headTpl += '     </div>'
    headTpl += ' </div>'

    // var $headTpl = $(headTpl)
    // $headTpl.find(".login_btn").on("click",function(){
    //     alert('login')
    // })
    $('body').prepend(headTpl)
    $('body').on('click', '.login_btn', function () {
        window.location.href = HOME.locationVal.origin + "/login.html"
    });

    $('body').on('click', '.login_txt_b', function () {
        if(HOME.getCookierl('HOMEistooken')){
            layer.open({
                type: 1
                , title: false //不显示标题栏
                , closeBtn: false
                , area: '300px;'
                , shade: 0.8
                , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                , btn: ['确定', '取消']
                , btnAlign: 'c'
                , moveType: 1 //拖拽模式，0或者1
                , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">确定要退出吗？</div>'
                , yes: function () {
                    $('.layui-layer-shade, .layui-layer').remove();
                    HOME.ajaxHOMEFn(
                        {
                            url: HOME.baseUrl.logout,
                            type: 'POST',
                            data: {}
                        },
                        function (data) {
                            window.open('/index.html', '_self');
                            HOME.clearCookierl()
                        }
                    )
                }
    
            }); 
        }else{
            layer.msg('您已经是退出状态')
        }
        
    })


})